using System.Collections.Generic;
using UnityEngine;

public class FallingObjectTransparency : MonoBehaviour
{
	private bool _isTransparent;

	private List<Renderer> _opaqueRenderers;

	private List<Renderer> _transparentRenderers;

	private bool _isRaycasted;

	public bool IsRaycasted
	{
		get
		{
			return _isRaycasted;
		}
		set
		{
			_isRaycasted = value;
		}
	}

	public void Init()
	{
		_opaqueRenderers = new List<Renderer>();
		_transparentRenderers = new List<Renderer>();
		Transform transform = UnityEngine.Object.Instantiate(base.transform);
		transform.gameObject.name = $"{base.transform.name} (Transparent)";
		transform.SetParent(base.transform);
		Collider[] componentsInChildren = transform.GetComponentsInChildren<Collider>();
		Collider[] array = componentsInChildren;
		foreach (Collider obj in array)
		{
			UnityEngine.Object.Destroy(obj);
		}
		Rigidbody component = transform.GetComponent<Rigidbody>();
		if ((bool)component)
		{
			UnityEngine.Object.Destroy(component);
		}
		FallingObject component2 = transform.GetComponent<FallingObject>();
		if ((bool)component2)
		{
			UnityEngine.Object.Destroy(component2);
		}
		AutomaticLOD[] componentsInChildren2 = transform.GetComponentsInChildren<AutomaticLOD>();
		AutomaticLOD[] array2 = componentsInChildren2;
		foreach (AutomaticLOD obj2 in array2)
		{
			UnityEngine.Object.Destroy(obj2);
		}
		AutomaticLODEnabler[] componentsInChildren3 = transform.GetComponentsInChildren<AutomaticLODEnabler>();
		AutomaticLODEnabler[] array3 = componentsInChildren3;
		foreach (AutomaticLODEnabler obj3 in array3)
		{
			UnityEngine.Object.Destroy(obj3);
		}
		FallingObjectBehaviour component3 = transform.GetComponent<FallingObjectBehaviour>();
		if ((bool)component3)
		{
			UnityEngine.Object.Destroy(component3);
		}
		FallingObjectTransparency component4 = transform.GetComponent<FallingObjectTransparency>();
		if ((bool)component4)
		{
			UnityEngine.Object.Destroy(component4);
		}
		transform.transform.localPosition = Vector3.zero;
		transform.transform.localRotation = Quaternion.identity;
		transform.transform.localScale = Vector3.one;
		Renderer[] componentsInChildren4 = base.transform.GetComponentsInChildren<Renderer>();
		_opaqueRenderers.AddRange(componentsInChildren4);
		componentsInChildren4 = transform.GetComponentsInChildren<Renderer>();
		_transparentRenderers.AddRange(componentsInChildren4);
		Renderer[] array4 = componentsInChildren4;
		foreach (Renderer renderer in array4)
		{
			renderer.material = TransparencyManager.Instance.TransparentMaterial;
		}
	}

	public void SetTransparent(bool state)
	{
		if (_isTransparent != state)
		{
			_isTransparent = state;
			foreach (Renderer opaqueRenderer in _opaqueRenderers)
			{
				opaqueRenderer.enabled = !state;
			}
			foreach (Renderer transparentRenderer in _transparentRenderers)
			{
				transparentRenderer.enabled = state;
			}
		}
	}
}
